    /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;
import Model.Boxel;
import Model.World;
import Model.World_Table;
import View.View;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;

/**
 *
 * @author Daniel
 */
public class Controller {

    //de 364 a 371
    private static void adaptMap(World w) {  //You should burn this into Mordor after you're done with it
    }
    private World_Table _table;
//private final HashMap<int, int> _boxelRef; //<int rgb, int type>
    private final int WIDTH = 8;
    private final int HEIGHT = 8;
    private static ArrayList<BufferedImage> _texture;
    private View view;

    private World_Table createWorldTable() {
        return new World_Table();
    }

    private World createWorld(String file) {
        return new World();
    }

    private Boxel createBoxel(int type) {
        return new Boxel();
    }

//    private /*Erase this later*/ static/*Erase this after testing*/ Boxel[] BItoBoxel(File in, int width, int height) {
//
//        ArrayList<BufferedImage> textaux = TextureLoad.decode(in, width, height);
//        Boxel[] out = new Boxel[textaux.size()];
//        for (int k = 0; k < textaux.size(); k++) {
//
//            Pixel[][] taux = new Pixel[textaux.get(k).getHeight()][textaux.get(k).getWidth()];
//
//            for (int i = 0; i < height; i++) {
//                for (int j = 0; j < width; j++) {
//                    taux[i][j] = new Pixel(textaux.get(k).getRGB(i, j));
//                }
//            }
//
//        }
//
//        return out;
//    }
    public Controller() { //TODO: maps load horribly. Find out why.
//        double start = System.currentTimeMillis();

        int width = 20, height = 20;


        _texture = TextureLoad.decode(new File("img/texturetest.png"), width, height);
        _texture.addAll(TextureLoad.decode(new File("img/font.png"), width, height));
        _texture.add(0, TextureLoad.loadFullFile(new File("img/bgtest.png")));
        _texture.add(0, TextureLoad.loadFullFile(new File("img/blank.png")));

        view = new View(height, width, 16, 25, null);

//        double end = System.currentTimeMillis() - start;
//        System.out.println("Time to Load: " + end);
    }

    public void init() {
        World w = MapInterpret.translateFromMap(new File("img/testmap.png"), _texture);

        World w1 = MapInterpret.translateFromMap(new File("img/testmapbg.png"), _texture);
        for(int i = 0; i < w.get_height(); i++){
            for(int j = 0; j < w.get_width(); j++){
                w1.set_Boxel(_texture.get(1), j, i);
            }
        }
        
        System.out.println(_texture.size());

        view.init();


        
        while (true) {
            double start = System.currentTimeMillis();
            
            view.paint(w1, null);
            view.paint(w,  null);
            //adaptMap(w);

            double end = System.currentTimeMillis() - start;

//            System.out.println("Time to Paint: " + end);
//            System.out.println("FPS: " + 1000/end);
        }
    }
}
